﻿//-----------------------------------------------------------------------
// <copyright file="IAuthorizationService.cs" company="Alan Rodrigues">
//     Copyright (c) Alan Rodrigues. All rights reserved.
// </copyright>
// <developed>Alan Rodrigues (operninha@gmail.com)</developed>
//-----------------------------------------------------------------------
using System;
using System.ServiceModel;
using System.ServiceModel.Web;

namespace Authorization
{

    [ServiceContract(Name = "AuthorizationService", Namespace = "http://authorizationservices/v1")]
    [DataContractFormat(Style = OperationFormatStyle.Document)]
    public interface IAuthorizationService
    {
        #region OperationCollection
        ///<summary>
        ///</summary>
        ///<param name="applicationName"></param>>
        ///<returns></returns>
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [OperationContract(Name = "GetAllOperations")]
        [WebInvoke(Method = "POST")]
        OperationCollection GetAllOperations(string applicationName);

        [OperationContract(Name = "GetAllOperationNames")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string[] GetAllOperationNames(string applicationName);

        //UriTemplate = "{applicationName}/Operations/?operationName={operationName}")]

        [OperationContract(Name = "GetOperation")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        Operation GetOperation(string applicationName, string operationName);

        //UriTemplate = "Operations/{applicationName}/Create/?name={operationName}&description={description}&id={operationId}")]
        [OperationContract(Name = "CreateOperation")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        Operation CreateOperation(string applicationName, string operationName, string description, int operationId);

        [OperationContract(Name = "OperationExists")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        //UriTemplate = "{applicationName}/Operations/{operationName}/Exists")]
        //[XmlSerializerFormat(Style = OperationFormatStyle.Document, Use = OperationFormatUse.Literal)]
        bool OperationExists(string applicationName, string operationName);

        [OperationContract(Name = "DeleteOperation", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        // UriTemplate = "{applicationName}/Operations/{operationName}/Delete")]
        void DeleteOperation(string applicationName, string operationName);

        [OperationContract(Name = "UpdateOperation", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        //UriTemplate = "{applicationName}/Operations/{operationName}/Update/")]
        void UpdateOperation(string applicationName, string operationName, string newOperationName,
                                 string newOperationDescription, int newOperationId);

        #endregion

        #region TaskCollection

        [OperationContract(Name = "GetAllTasks")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        // UriTemplate = "{applicationName}/Tasks/{scopeName}/All")]
        TaskCollection GetAllTasks(string applicationName, string scopeName);

        ///<summary>
        /// Retorna os names dos <see cref="RoleCollection"/> da <see cref="Application"/>
        ///</summary>
        ///<param name="applicationName">Name da <see cref="Application"/></param>
        ///<param name="scopeName">Name do <see cref="Scope"/></param>
        ///<returns>Lista com os names das <see cref="OperationCollection"/></returns>
        [OperationContract(Name = "GetAllTaskNames")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string[] GetAllTaskNames(string applicationName, string scopeName);

        [OperationContract(Name = "GetTask")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle =  WebMessageBodyStyle.WrappedRequest)]
        Task GetTask(string applicationName, string scopeName, string taskName);

        [OperationContract(Name = "CreateTask")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        Task CreateTask(string applicationName, string scopeName, string taskName, string description);

        [OperationContract(Name = "DeleteTask", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void DeleteTask(string applicationName, string scopeName, string taskName);

        [OperationContract(Name = "UpdateTask", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void UpdateTask(string applicationName, string scopeName, string taskName, string newTaskName, string newDescription);

        [OperationContract(Name = "TaskExists")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        //[XmlSerializerFormat(Style = OperationFormatStyle.Document, Use = OperationFormatUse.Literal)]
        bool TaskExists(string applicationName,  string scopeName, string taskName);

        [OperationContract(Name = "GetTaskNamesInTask")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         string[] GetTaskNamesInTask(string applicationName, string scopeName, string taskName);

        [OperationContract(Name = "GetTasksInTask")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         TaskCollection GetTasksInTask(string applicationName, string scopeName, string taskName);

        [OperationContract(Name = "GetOperationNamesInTask")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         string[] GetOperationNamesInTask(string applicationName, string scopeName, string taskName);

        [OperationContract(Name = "GetOperationsInTask")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         OperationCollection GetOperationsInTask(string applicationName, string scopeName, string taskName);

        [OperationContract(Name = "AddOperationToTask")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         void AddOperationToTask(string applicationName, string scopeName, string taskName, string operationName);

        [OperationContract(Name = "RemoveOperationFromTask")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         void RemoveOperationFromTask(string applicationName, string scopeName, string  taskName, string  operationName);

        [OperationContract(Name = "RemoveTaskFromTask")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         void RemoveTaskFromTask(string applicationName, string scopeName, string parentTaskName, string childTaskName);

        [OperationContract(Name = "AddTaskToTask")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         void AddTaskToTask(string applicationName, string parentScopeName, string parentTaskName, string childTaskName);
        
        #endregion

        #region RoleDefinitions

        [OperationContract(Name = "GetAllRoleDefinitions")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        RoleDefinitionCollection GetAllRoleDefinitions(string applicationName, string scopeName);


        ///<summary>
        /// Retorna os names dos <see cref="RoleCollection"/> da <see cref="Application"/>
        ///</summary>
        ///<param name="applicationName">Name da <see cref="Application"/></param>
        ///<param name="scopeName">Name do <see cref="Scope"/></param>
        ///<returns>Lista com os names das <see cref="OperationCollection"/></returns>
        [OperationContract(Name = "GetAllRoleDefinitionNames")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string[] GetAllRoleDefinitionNames(string applicationName, string scopeName);

        [OperationContract(Name = "GetRoleDefinition")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        RoleDefinition GetRoleDefinition(string applicationName, string scopeName, string roleDefinitionName);

        [OperationContract(Name = "RoleDefinitionExists")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
        BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        bool RoleDefinitionExists(string applicationName, string scopeName, string roleDefinitionName);
   
        [OperationContract(Name = "CreateRoleDefinition")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        RoleDefinition CreateRoleDefinition(string applicationName, string scopeName, string roleDefinitionName, string description);

        [OperationContract(Name = "DeleteRoleDefinition", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void DeleteRoleDefinition(string applicationName, string scopeName, string roleDefinitionName);

        [OperationContract(Name = "UpdateRoleDefinition", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void UpdateRoleDefinition(string applicationName, string scopeName, string roleDefinitionName, string newRoleDefinitionName, string newDescription);

        [OperationContract(Name = "GetRoleAssignments", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        RoleAssignmentCollection GetRoleAssignments(string applicationName, string scopeName,
                                                           string roleDefinitionName, string scopeNameToSearch,
                                                           bool isRecursive);

        [OperationContract(Name = "GetRoleDefinitionNamesInRoleDefinition", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string[] GetRoleDefinitionNamesInRoleDefinition(string applicationName, string scopeName,
                                                        string roleDefinitionName);


        [OperationContract(Name = "GetRoleDefinitionInRoleDefinition", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        RoleDefinitionCollection GetRoleDefinitionInRoleDefinition(string applicationName, string scopeName,
                                                                   string roleDefinitionName);


        [OperationContract(Name = "RemoveRoleDefinitionFromRoleDefinition", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void RemoveRoleDefinitionFromRoleDefinition(string applicationName, string scopeName,
                                                    string parentRoleDefinitionName, string childRoleDefinitionName);


        [OperationContract(Name = "AddRoleDefinitionToRoleDefinition", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void AddRoleDefinitionToRoleDefinition(string applicationName, string parentScopeName,
                                               string parentRoleDefinitionName, string childRoleDefinitionName);

        [OperationContract(Name = "GetTaskNamesInRoleDefinition", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string[] GetTaskNamesInRoleDefinition(string applicationName, string scopeName, string roleDefinitionName);


        [OperationContract(Name = "GetTasksInRoleDefinition", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        TaskCollection GetTasksInRoleDefinition(string applicationName, string scopeName, string roleDefinitionName);

        [OperationContract(Name = "GetOperationNamesInRoleDefinition", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string[] GetOperationNamesInRoleDefinition(string applicationName, string scopeName, string roleDefinitionName);


        [OperationContract(Name = "GetOperationsInRoleDefinition", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        OperationCollection GetOperationsInRoleDefinition(string applicationName, string scopeName,
                                                          string roleDefinitionName);


        [OperationContract(Name = "AddOperationToRoleDefinition", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void AddOperationToRoleDefinition(string applicationName, string scopeName, string roleDefinitionName,
                                     string operationName);


        [OperationContract(Name = "RemoveOperationFromRoleDefinition", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void RemoveOperationFromRoleDefinition(string applicationName, string scopeName, string roleDefinitionName,
                                               string operationName);

        [OperationContract(Name = "RemoveTaskFromRoleDefinition", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void RemoveTaskFromRoleDefinition(string applicationName, string scopeName, string roleDefinitionName,
                                          string childTaskName);

        [OperationContract(Name = "AddTaskToRoleDefinition", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void AddTaskToRoleDefinition(string applicationName, string parentScopeName, string roleDefinitionName,
                                     string childTaskName);




        #endregion

        #region RoleAssignment

        [OperationContract(Name = "GetAllRoleAssignments")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        RoleAssignmentCollection GetAllRoleAssignments(string applicationName, string scopeName);

        ///<summary>
        /// Retorna os names dos <see cref="RoleCollection"/> da <see cref="Application"/>
        ///</summary>
        ///<param name="applicationName">Name da <see cref="Application"/></param>
        ///<param name="scopeName">Name do <see cref="Scope"/></param>
        ///<returns>Lista com os names das <see cref="OperationCollection"/></returns>
        [OperationContract(Name = "GetAllRoleAssignmentNames")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string[] GetAllRoleAssignmentNames(string applicationName, string scopeName);

        [OperationContract(Name = "GetRoleAssignment")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        RoleAssignment GetRoleAssignment(string applicationName, string scopeName, string roleAssignmentName);

        [OperationContract(Name = "RoleAssignmentExists")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
        BodyStyle = WebMessageBodyStyle.WrappedRequest )]
        bool RoleAssignmentExists(string applicationName, string scopeName, string roleName);

        [OperationContract(Name = "FindUsersInRoleAssignment")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string[] FindUsersInRoleAssignment(string usernameToMatch, string applicationName, string scopeName, string roleAssignmentName);

        [OperationContract(Name = "GetUsersInRoleAssignment")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string[] GetUsersInRoleAssignment(string applicationName, string scopeName, string roleAssignmentName);

        [OperationContract(Name = "RemoveUsersFromRoleAssignments")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]  
        void RemoveUsersFromRoleAssignments(string applicationName, string scopeName, string[] usernames, string[] roleAssignmentNames);

        [OperationContract(Name = "RemoveUserNameFromRoleAssignments")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void RemoveUserNameFromRoleAssignments(string applicationName, string scopeName, string[] usernames, string[] roleAssignmentNames);
   
        [OperationContract(Name = "CreateRoleAssignment")]
        [FaultContract(typeof (ArgumentNullException))]
        [FaultContract(typeof (AuthorizationServiceError))]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        RoleAssignment CreateRoleAssignment(string applicationName, string scopeName, string roleDefinitionName,
                                            string roleAssignmentName, string description);

        [OperationContract(Name = "DeleteRoleAssignment", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void DeleteRoleAssignment(string applicationName, string scopeName, string roleName);

        [OperationContract(Name = "UpdateRoleAssignment", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void UpdateRoleAssignment(string applicationName, string scopeName, string roleName, string newRoleName, string newDescription);

        [OperationContract(Name = "AddUserNamesToRoleAssignments", IsOneWay = false)]
        [FaultContract(typeof (ArgumentNullException))]
        [FaultContract(typeof (AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
            BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void AddUserNamesToRoleAssignments(string applicationName, string scopeName, string[] usernames, string[] roleNames);

        [OperationContract(Name = "AddUsersToRoleAssignments", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
            BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void AddUsersToRoleAssignments(string applicationName, string scopeName, string[] SIDs, string[] roleNames);

        /// <summary>
        /// Realiza a remocao de todas as permissoes de um determinado usuario levando em conta
        /// os filtros informados.
        /// Jose Mauro - Rerum 18/05/2011 IM120338
        /// </summary>
        /// <param name="username">nome do usuario.</param>
        /// <param name="applicationName">nome das aplicacoes a serem consideradas.</param>
        /// <param name="scopeName">nome dos escopos a serem considerados.</param>
        /// <param name="roleAssignments">nome dos perfis que o usuario esta associado.</param>
        /// <returns></returns>
        [OperationContract(Name = "RemoveRoleAssignments", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
            BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        bool RemoveRoleAssignments(string username, string[] applicationName, string[] scopeName, string[] roleAssignments);

        /// <summary>
        /// Recupera todos os perfis que satisfacam os filtros recebidos.
        /// Jose Mauro - Rerum 18/05/2011 IM120338
        /// </summary>
        /// <param name="username">nome do usuario.</param>
        /// <param name="applicationName">nome das aplicacoes a serem consideradas.</param>
        /// <param name="scopeName">nome dos escopos a serem considerados.</param>
        /// <returns></returns>
        [OperationContract(Name = "GetAllRoleAssignmentsByUser", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
            BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        RoleAssignmentUserCollection GetAllRoleAssignmentsByUser(string username, string[] applicationName, string[] scopeName);

        #endregion

        #region ScopeCollection

        [OperationContract(Name = "GetAllScopes")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        ScopeCollection GetAllScopes(string applicationName);

        [OperationContract(Name = "GetScope")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        Scope GetScope(string applicationName, string scopeName);

        /// <summary>
        ///  Retorna os names dos <see cref="ScopeCollection"/> da <see cref="Application"/>
        /// </summary>
        /// <param name="applicationName">Name da <see cref="Application"/></param>
        /// <returns>Lista com os names dos <see cref="ScopeCollection"/></returns>
        [OperationContract(Name = "GetAllScopeNames")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string[] GetAllScopeNames(string applicationName);

        [OperationContract(Name = "ScopeExists")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        bool ScopeExists(string applicationName, string scopeName);

        [OperationContract(Name = "CreateScope")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        Scope CreateScope(string applicationName, string scopeName, string description);

        [OperationContract(Name = "DeleteScope", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void DeleteScope(string applicationName, string scopeName);

        [OperationContract(Name = "UpdateScope", IsOneWay = false)]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void UpdateScope(string applicationName, string scopeName, string newScopeName, string newDescription);
        
        [OperationContract(Name = "GetAllAssignedScopesForUser")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string[] GetAllAssignedScopesForUser(string applicationName, string userName);

        [OperationContract(Name = "GetAssignedScopesPageForUser")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        AuthorizationResponseWithCursor<string[]> GetAssignedScopesPageForUser(string applicationName, string userName, int pageSize, string cursor);

        [OperationContract(Name = "GetAllAssignedScopesForUserWithFilter")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string[] GetAllAssignedScopesForUser(string applicationName, string userName, string filterPattern);
              
      
        #endregion

        #region ApplicationGroup
        [OperationContract(Name = "GetAllApplicationGroups")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         ApplicationGroupCollection GetAllApplicationGroups(string applicationName, string scopeName);

        [OperationContract(Name = "GetAllApplicationGroupNames")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         string[] GetAllApplicationGroupNames(string applicationName, string scopeName);


        [OperationContract(Name = "ApplicationGroupExists")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         bool ApplicationGroupExists(string applicationName, string scopeName, string applicationGroupName);


        [OperationContract(Name = "GetApplicationGroup")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         ApplicationGroup GetApplicationGroup(string applicationName, string scopeName, string applicationGroupName);

        [OperationContract(Name = "CreateApplicationGroup")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         ApplicationGroup CreateApplicationGroup(string applicationName, string scopeName, string applicationGroupName, string description);
        
        [OperationContract(Name = "DeleteApplicationGroup")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
          void DeleteApplicationGroup(string applicationName, string scopeName, string applicationGroupName);

        [OperationContract(Name = "UpdateApplicationGroup")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         void UpdateApplicationGroup(string applicationName, string scopeName, string applicationGroupName, string newApplicationGroupName, string newDescription);
        
        [OperationContract(Name = "AddUsersToApplicationGroup")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
        BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         void AddUsersToApplicationGroup(string applicationName, string scopeName, string[] Sids, string[] applicationGroupNames);

        [OperationContract(Name = "AddUserNamesToApplicationGroups")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
        BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         void AddUserNamesToApplicationGroups(string applicationName, string scopeName, string[] usernames, string[] applicationGroupNames);

        [OperationContract(Name = "FindUsersInApplicationGroup")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
        BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         string[] FindUsersInApplicationGroup(string usernameToMatch, string applicationName, string scopeName, string applicationGroupName);
        
         [OperationContract(Name = "GetUsersInApplicationGroup")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
        BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         string[] GetUsersInApplicationGroup(string applicationName, string scopeName, string applicationGroupName);
        
        [OperationContract(Name = "RemoveUsersFromApplicationGroups")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
        BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         void RemoveUsersFromApplicationGroups(string applicationName, string scopeName, string[] usernames, string[] applicationGroupsName);
       
        #endregion

        #region ApplicationCollection

        /// <summary>
        /// Retorna <see cref="ApplicationCollection"/>
        /// </summary>
        /// <returns>Lista de <see cref="ApplicationCollection"/></returns>
        [OperationContract(Name = "GetAllApplications")]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        ApplicationCollection GetAllApplications();

        /// <summary>
        /// Retorna <see cref="Application"/>
        /// </summary>
        /// <returns><see cref="Application"/></returns>
        [OperationContract(Name = "GetApplication")]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        Application GetApplication(string applicationName);


        /// <summary>
        /// Retorna <see cref="Application"/>
        /// </summary>
        /// <returns><see cref="Application"/></returns>
        [OperationContract(Name = "DeleteApplication")]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void DeleteApplication(string applicationName);


        /// <summary>
        /// Retorna <see cref="Application"/>
        /// </summary>
        /// <returns><see cref="Application"/></returns>
        [OperationContract(Name = "CreateApplication")]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        Application CreateApplication(string storeName, string applicationName, string version, string Description, string applicationData);

        /// <summary>
        /// Retorna <see cref="Application"/>
        /// </summary>
        /// <returns><see cref="Application"/></returns>
        [OperationContract(Name = "UpdateApplication")]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        Application UpdateApplication(string applicationName, string newApplicationName, string newVersion, string newDescription, string newApplicationData);

        /// <summary>
        ///  Retorna os names dos <see cref="ScopeCollection"/> da <see cref="Application"/>
        /// </summary>
        /// <returns>Lista com os names dos <see cref="ScopeCollection"/></returns>
        [OperationContract(Name = "GetAllApplicationNames")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string[] GetAllApplicationNames();

        [OperationContract(Name = "ApplicationExists")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        bool ApplicationExists(string applicationName);

        //[OperationContract(Name = "CreateApplication")]
        //[FaultContract(typeof(ArgumentNullException))]
        //[FaultContract(typeof(AuthorizationServiceError))]
        //[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml,
        // ResponseFormat = WebMessageFormat.Xml,
        // BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        //Task CreateApplication(string applicationName, string description, string version);

        //[OperationContract(Name = "DeleteApplication", IsOneWay = false)]
        //[FaultContract(typeof(ArgumentNullException))]
        //[FaultContract(typeof(AuthorizationServiceError))]
        //[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml,
        // ResponseFormat = WebMessageFormat.Xml,
        // BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        //void DeleteApplication(string applicationName);

        //[OperationContract(Name = "UpdateApplication", IsOneWay = false)]
        //[FaultContract(typeof(ArgumentNullException))]
        //[FaultContract(typeof(AuthorizationServiceError))]
        //[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml,
        // ResponseFormat = WebMessageFormat.Xml,
        // BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        //void UpdateApplication(string applicationName, string newApplicationName, string newDescription, string newVersion);

        #endregion

        #region Store

        [OperationContract(Name = "GetAllStoreNames")]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml,
         ResponseFormat = WebMessageFormat.Xml,
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string[] GetAllStoreNames();

        [OperationContract(Name = "GetDefaultStoreName")]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml,
         ResponseFormat = WebMessageFormat.Xml,
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string GetDefaultStoreName();

        [OperationContract(Name = "UpdateServiceCache")]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        void UpdateServiceCache();


        [OperationContract(Name = "ExportApplication")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string ExportApplication(string applicationName, bool isToMerge, bool isCopyWithAdministrators, bool isCopyWithUsers);

        [OperationContract(Name = "ImportApplication")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
          BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string ImportApplication(string applicationName, string xmlData, string store, bool isToMerge);



        #endregion     

        #region IClientAuthorizationService
        ///<summary>
        /// Gets <see cref="OperationCollection"/> from <see cref="ApplicationCollection"/> to authenticated user
        ///</summary>
        ///<param name="userName"></param>
        ///<param name="applicationName"> <see cref="Application"/> name</param>
        /// <param name="scopeName">returns operationIds from the <see cref="Scope"/>, null will return from azmanApplication root</param>
        ///<returns><see cref="OperationCollection"/> from choosen azmanApplication and scope</returns>
        [OperationContract(Name = "GetOperationsForUser")]
        [FaultContract(typeof(ArgumentNullException))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        OperationCollection GetOperationsForUser(string userName, string applicationName, string scopeName);

        [OperationContract(Name = "GetOperationNamesForUser")]
        [FaultContract(typeof(ArgumentNullException))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string[] GetOperationNamesForUser(string userName, string applicationName, string scopeName);

        [OperationContract(Name = "GetTasksForUser")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        TaskCollection GetTasksForUser(string userName, string applicationName, string scopeName);

        [OperationContract(Name = "GetRoleAssignmentsForUser")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        RoleAssignmentCollection GetRoleAssignmentsForUser(string userName, string applicationName, string scopeName);

        [OperationContract(Name = "GetRoleAssignmentsNamesForUser")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string[] GetRoleAssignmentsNamesForUser(string userName, string applicationName, string scopeName);

        [OperationContract(Name = "GetTaskNamesForUser")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        string[] GetTaskNamesForUser(string userName, string applicationName, string scopeName);


        [OperationContract(Name = "IsUserInRoleAssignment")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        bool IsUserInRoleAssignment(string userName, string applicationName, string scopeName, string roleAssignmentName);

        [OperationContract(Name = "IsUserInApplicationGroup")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
         bool IsUserInApplicationGroup(string userName, string applicationName, string scopeName, string applicationGroupName);

        [OperationContract(Name = "IsUserInTask")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
        BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        bool IsUserInTask(string userName, string applicationName, string taskName, string[] scopeNames);

        //[XmlSerializerFormat(Style = OperationFormatStyle.Document, Use = OperationFormatUse.Literal)]
       
        [OperationContract(Name = "AccessCheck")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
        BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        bool AccessCheck(string userName, string applicationName, int operationId, string scopeName);

        //TODO: Adicionar opcoes para verificar por role e outras informacoes...

        //[XmlSerializerFormat(Style = OperationFormatStyle.Document, Use = OperationFormatUse.Literal)]
        [OperationContract(Name = "AccessCheckByName")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
        BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        bool AccessCheck(string userName, string applicationName, string operationName, string scopeName);

        [OperationContract(Name = "BulkAccessCheck")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        int[] AccessCheck(string userName, string applicationName, int[] operationIds, string[] scopeNames);

        [OperationContract(Name = "BulkAccessCheckByName")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        OperationCollection AccessCheck(string userName, string applicationName, string[] operationNames, string[] scopeNames);

        
        [OperationContract(Name = "BulkAccessCheckByNameInAnyScope")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST",
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        OperationCollection AccessCheck(string userName, string applicationName, string scopeFilter, string[] operationNames);


        //[XmlSerializerFormat(Style = OperationFormatStyle.Document, Use = OperationFormatUse.Literal)]
        [OperationContract(Name = "BulkAccessCheckWithRules")]
        [FaultContract(typeof(ArgumentNullException))]
        [FaultContract(typeof(AuthorizationServiceError))]
        [WebInvoke(Method = "POST", 
        BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        bool AccessCheck(string userName, string applicationName, int operationId, string scopeName, string[] variableNames, object[] variableValues);
        #endregion
    }
}
